package indi.gao.thread.future;

import com.alibaba.fastjson.JSONObject;
import indi.gao.thread.callable.CallableTest;
import indi.gao.thread.service.BaseService;
import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.*;

/**
 * @author :gaolei
 * @version :v1.0
 * @projectName :GLUtil
 * @description :
 * @createDate :2021/8/9 2:58 下午
 */
public class FutureTest {

    @Test
    public void test() throws ExecutionException, InterruptedException {
        BaseService.setInheritableThreadLocal("主线程set");
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(50, 50, 100l, TimeUnit.SECONDS, new ArrayBlockingQueue<>(30), new FutureTestFactory(), new FutureTestRejectPolicy());
        List<String> strings = new ArrayList<>();
        for (int i = 0; i < 1000; i++) {
            Future<String> submit = threadPoolExecutor.submit(new CallableTest());
//            strings.add(submit.get());
        }
//        System.out.println(JSONObject.toJSONString(strings));
        BaseService.setInheritableThreadLocal("主线程set1");
    }
}
